home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ShareWare OnLine 2
/
ShareWare OnLine Volume 2 (CMS Software)(1993).iso
/
os2
/
remin301.zip
/
REMIN300.ZIP
/
INIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-10
|
10KB
|
330 lines
/***************************************************************/
/* */
/* INIT.C */
/* */
/* Initialize remind; perform certain tasks between */
/* iterations in calendar mode; do certain checks after end */
/* in normal mode. */
/* */
/* This file is part of REMIND. */
/* Copyright (C) 1992 by David F. Skoll. */
/* */
/***************************************************************/
#include "config.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <ctype.h>
#include "types.h"
#include "protos.h"
#include "expr.h"
#include "globals.h"
#include "err.h"
#include "version.h"
/***************************************************************
*
* Command line options recognized:
*
* -n = Output next trigger date of each reminder in
* simple calendar format.
* -r = Disallow RUN mode
* -c[n] = Produce a calendar for n months (default = 1)
* -w[n] = Specify output device width (default = 80)
* -s[n] = Produce calendar in "simple calendar" format
* -v = Verbose mode
* -o = Ignore ONCE directives
* -a = Don't issue timed reminders which will be queued
* -q = Don't queue timed reminders
* -t = Trigger all reminders (infinite delta)
* -h = Hush mode
* -f = Do not fork
* -dchars = Debugging mode: Chars are:
* e = Echo input lines
* x = Display expression evaluation
* t = Display trigger dates
* v = Dump variables at end
* l = Display entire line in error messages
* -e = Send messages normally sent to stderr to stdout instead
* -z[n] = Daemon mode waking up every n (def 5) minutes.
* -bn = Time format for cal (0, 1, or 2)
* -xn = Max. number of iterations for SATISFY
*
**************************************************************/
/* For parsing an integer */
#define PARSENUM(var, s) \
var = 0; \
while (isdigit(*(s))) { \
var *= 10; \
var += *(s) - '0'; \
s++; \
}
static char *BadDate = "Illegal date on command line\n";
/***************************************************************/
/* */
/* InitRemind */
/* */
/* Initialize the system - called only once at beginning! */
/* */
/***************************************************************/
#ifdef HAVE_PROTOS
PUBLIC void InitRemind(int argc, char *argv[])
#else
void InitRemind(argc, argv)
int argc;
char *argv[];
#endif
{
char *arg;
int i;
int y, m, d;
Token tok;
y = NO_YR;
m = NO_MON;
d = NO_DAY;
RealToday = SystemDate(&CurYear, &CurMon, &CurDay);
if (RealToday < 0) {
fprintf(ErrFp, "Illegal system date: Year is less than %d\n", BASE);
exit(1);
}
JulianToday = RealToday;
FirstYear = -1;
FromJulian(JulianToday, &CurYear, &CurMon, &CurDay);
/* Parse the command-line options */
i = 1;
while (i < argc) {
arg = argv[i];
if (*arg != '-') break; /* Exit the loop if it's not an option */
i++;
arg++;
while (*arg) {
switch(*arg++) {
case 'n':
case 'N':
NextMode = 1;
#ifdef HAVE_QUEUED
DontQueue = 1;
#endif
break;
case 'r':
case 'R':
RunDisabled = 1;
break;
case 'o':
case 'O':
IgnoreOnce = 1;
break;
case 't':
case 'T':
InfiniteDelta = 1;
break;
case 'e':
case 'E':
ErrFp = stdout;
break;
case 'h':
case 'H':
Hush = 1;
break;
#ifdef HAVE_QUEUED
case 'z':
case 'Z':
DontFork = 1;
PARSENUM(Daemon, arg);
if (Daemon<5) Daemon=5;
else if (Daemon>60) Daemon=60;
break;
case 'a':
case 'A':
DontIssueAts = 1;
break;
case 'q':
case 'Q':
DontQueue = 1;
break;
case 'f':
case 'F':
DontFork = 1;
break;
#endif
case 'c':
case 'C':
DoCalendar = 1;
if (*arg == '+') {
arg++;
PARSENUM(CalWeeks, arg);
if (!CalWeeks) CalWeeks = 1;
} else {
PARSENUM(CalMonths, arg);
if (!CalMonths) CalMonths = 1;
}
break;
case 's':
case 'S':
DoSimpleCalendar = 1;
PARSENUM(CalMonths, arg);
if (!CalMonths) CalMonths = 1;
break;
case 'w':
case 'W':
PARSENUM(CalWidth, arg);
if (CalWidth < 80) CalWidth = 80;
break;
case 'd':
case 'D':
while (*arg) {
switch(*arg++) {
case 'e': case 'E': DebugFlag |= DB_ECHO_LINE; break;
case 'x': case 'X': DebugFlag |= DB_PRTEXPR; break;
case 't': case 'T': DebugFlag |= DB_PRTTRIG; break;
case 'v': case 'V': DebugFlag |= DB_DUMP_VARS; break;
case 'l': case 'L': DebugFlag |= DB_PRTLINE; break;
default:
fprintf(ErrFp, "Unknown debug flag '%c'\n", *(arg-1));
}
}
break;
case 'v':
case 'V':
DebugFlag |= DB_PRTLINE;
ShowAllErrors = 1;
break;
case 'b':
case 'B':
PARSENUM(ScFormat, arg);
if (ScFormat<0 || ScFormat>2) ScFormat=SC_AMPM;
break;
case 'x':
case 'X':
PARSENUM(MaxSatIter, arg);
if (MaxSatIter < 10) MaxSatIter=10;
break;
default:
fprintf(ErrFp, "Unknown option '%c'\n", *(arg-1));
}
}
}
/* Get the filename. */
if (i >= argc) {
Usage();
exit(1);
}
InitialFile = argv[i];
i++;
/* Get the date, if any */
if (i < argc) {
while (i < argc) {
arg = argv[i++];
FindToken(arg, &tok);
switch (tok.type) {
case T_Month:
if (m != NO_MON) Usage();
else m = tok.val;
break;
case T_Day:
if (d != NO_DAY) Usage();
else d = tok.val;
break;
case T_Year:
if (y != NO_YR) Usage();
else y = tok.val;
break;
default: Usage();
}
}
/* Must supply date in the form: day, mon, yr OR mon, yr */
if (m == NO_MON || y == NO_YR) Usage();
if (d == NO_DAY) d=1;
if (d > DaysInMonth(m, y)) {
fprintf(ErrFp, BadDate);
Usage();
}
JulianToday = Julian(y, m, d);
if (JulianToday == -1) {
fprintf(ErrFp, BadDate);
Usage();
}
CurYear = y;
CurMon = m;
CurDay = d;
if (JulianToday != RealToday) IgnoreOnce = 1;
}
/* Set JulFirst */
JulFirst = Julian(CurYear, 0, 1);
FirstYear = CurYear;
}
/***************************************************************/
/* */
/* Usage */
/* */
/* Print the usage info. */
/* */
/***************************************************************/
#ifdef HAVE_PROTOS
PUBLIC void Usage(void)
#else
void Usage()
#endif
{
fprintf(ErrFp, "\nREMIND %s Copyright 1992 by David F. Skoll\n\n", VERSION);
fprintf(ErrFp, "Usage: remind [options] filename [date]\n\n");
fprintf(ErrFp, "Options:\n");
fprintf(ErrFp, " -n Output next occurrence of reminders in simple format\n");
fprintf(ErrFp, " -r Disable RUN directives\n");
fprintf(ErrFp, " -c[n] Produce a calendar for n (default 1) months\n");
fprintf(ErrFp, " -c+[n] Produce a calendar for n (default 1) weeks\n");
fprintf(ErrFp, " -w[n] Specify width (default 80) of calendar output\n");
fprintf(ErrFp, " -s[n] Produce 'simple calendar' for n (1) months\n");
fprintf(ErrFp, " -v Verbose mode\n");
fprintf(ErrFp, " -o Ignore ONCE directives\n");
fprintf(ErrFp, " -t Trigger all future reminders regardless of delta\n");
fprintf(ErrFp, " -h 'Hush' mode - be very quiet\n");
#ifdef HAVE_QUEUED
fprintf(ErrFp, " -a Don't trigger timed reminders immediately - just queue them\n");
fprintf(ErrFp, " -q Don't queue timed reminders\n");
fprintf(ErrFp, " -f Trigger timed reminders by staying in foreground\n");
fprintf(ErrFp, " -z[n] Enter daemon mode, waking every n (5) minutes.\n");
#endif
fprintf(ErrFp, " -d... Debug: e=echo x=expr-eval t=trig v=dumpvars l=showline\n");
fprintf(ErrFp, " -e Divert messages normally sent to stderr to stdout\n");
fprintf(ErrFp, " -b[n] Time format for cal: 0=am/pm, 1=24hr, 2=none\n");
fprintf(ErrFp, " -x[n] Iteration limit for SATISFY clause (def=150)\n");
exit(1);
}